package com.thinkit.bigdata.web.service.impl.bus;

import com.thinkit.bigdata.web.dao.bus.BusModelMapper;
import com.thinkit.bigdata.web.dao.bus.BusModelRuleMapper;
import com.thinkit.bigdata.web.dao.bus.BusWorkModelMapper;
import com.thinkit.bigdata.web.model.bus.*;
import com.thinkit.bigdata.web.service.bus.BusWorkModelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * Created by hccl on 2018/9/26.
 */
@Service
public class BusWorkModelServiceImpl implements BusWorkModelService {

    @Resource
    private BusWorkModelMapper busWorkModelMapper;

    @Resource
    private BusModelMapper busModelMapper;

    @Resource
    private BusModelRuleMapper busModelRuleMapper;

    @Override
    public int insertSelective(BusWorkModel record) {
        return busWorkModelMapper.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(BusWorkModel record) {
        return busWorkModelMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int deleteByExample(BusWorkModelExample example) {
        return busWorkModelMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return busWorkModelMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<BusWorkModel> selectByExample(BusWorkModelExample example) {
        return busWorkModelMapper.selectByExample(example);
    }

    @Override
    public List<Map<String, Object>> findModel(BusWorkModelExample example) {
        List<Map<String, Object>> mapList = new ArrayList<>();
        List<BusWorkModel> workModels = busWorkModelMapper.selectByExample(example);
        for (BusWorkModel wm : workModels) {
            Map<String, Object> map = new HashMap<>();
            map.put("modelid", wm.getModelid());
            map.put("workid", wm.getWorkid());
            map.put("scores", wm.getScores());
            map.put("id", wm.getId());
            BusModelRuleExample example1 = new BusModelRuleExample();
            example1.createCriteria().andModelidEqualTo(wm.getModelid());
            List<BusModelRule> mrs = busModelRuleMapper.selectByExample(example1);
            BusModel model = busModelMapper.selectByPrimaryKey(wm.getModelid());
            if (model != null) {
                model.setModelrulelist(mrs);
                map.put("model", model);
            }
            mapList.add(map);
        }
        return mapList;
    }
}
